package com.hainabo.mgcmall.api.wx;

import com.hainabo.bootside.core.common.ReturnVO;
import com.hainabo.mgcmall.dao.PassengerRespository;
import com.hainabo.mgcmall.model.PassengerInfo;
import com.hainabo.mgcmall.util.JsonUtil;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.Map;

/**
 * Created by guoshihao on 2017/11/30.
 * 实名认证
 */
@Api(value = "/wx/passenger")
@Component
@Path("/wx/passenger")
@Produces(MediaType.APPLICATION_JSON)
@Slf4j
public class WxPassengerResource {
    @Autowired
    private PassengerRespository passengerRespository;

    @POST
    @Path("getInfo")
    public ReturnVO getInfo(String json){
        Map param = JsonUtil.toHashMap(json);
        Long id = Long.valueOf(param.get("wxUserId").toString());
        PassengerInfo passengerInfo = passengerRespository.getInfo(id);
        return new ReturnVO(passengerInfo);
    }

    @POST
    @Path("save")
    public ReturnVO save(String json){
        Map param = JsonUtil.toHashMap(json);
        PassengerInfo PassengerInfo = JsonUtil.toBean(param.get("passengerInfo"),PassengerInfo.class);
        return new ReturnVO(passengerRespository.save(PassengerInfo));
    }
}